package exercises.interfaces;

import java.util.Random;

interface Game { void  play(); }

interface GameFactory { Game getGame(); }

class FlipCoin implements Game {
    Random rand = new Random();
    public void play() {
        System.out.println("flip a coin");
        switch (rand.nextInt(2)) {
            case 0: System.out.println("字"); return;
            case 1: System.out.println("花"); return;
            default: System.out.println("中"); return;
        }
    }
}

class FlipCoinFactory implements GameFactory {
    public Game getGame() {
        return new FlipCoin();
    }
}

class RollDice implements Game {
    Random rand = new Random();
    public void play() {
        System.out.println("roll a dice");
        System.out.println(rand.nextInt(6) + 1);
    }
}

class RollDiceFactory implements GameFactory {
    public Game getGame() {
        return new RollDice();
    }
}

public class Game19 {
    public static void playGame(GameFactory factory) {
        Game g = factory.getGame();
        g.play();
    }
    public static void main(String[] args) {
        playGame(new FlipCoinFactory());
        playGame(new RollDiceFactory());
    }
}
